﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.Web.Services;
using System.Diagnostics;

public partial class RemoveAllocation : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetData();

        }
    }
    private void GetData()
    {
        if (hdnInput.Value == "search")
        {
            DataSet objDs;
            objDs = new UserMasterBAL().GetCandidateRemaining(txtRegNum.Text.Trim());
            gvStatusDashboard.DataSource = objDs;
            gvStatusDashboard.DataBind();
        }
    }
    protected void gvStatusDashboard_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvStatusDashboard.PageIndex = e.NewPageIndex;
        GetData();
       
    }
    protected void BtnSearch_OnClick(object sender, EventArgs e)
    {
        try
        {
            gvStatusDashboard.Visible = true;

            hdnInput.Value = "search";
            GetData();
            //Clear();
        }
        catch (Exception ex)
        {
           // lblErrorMessage.Text = "Error : " + ex.Message;
            //ex.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }

    }
   
   
    protected void BtnClear_OnClick(object sender, EventArgs e)
    {
        try
        {
            gvStatusDashboard.Visible = false;
           // btnDownload.Visible = false;
                       //txtState.Text = string.Empty;

            //lblErrorMessage.Text = string.Empty;

            //ddlState.SelectedValue = string.Empty;
            hdnInput.Value = string.Empty;
            //txtLanguageId.Text = "";
            //GetData();
        }
        catch (Exception ex)
        {
            //lblErrorMessage.Text = "Error : " + ex.Message;
        }
    }
        

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        hdnInput.Value = "search";
        GetData();
    }
    protected void lnkDel_Click(object sender, EventArgs e)
    {
  
        //string strregistrationID = Convert.ToString(gvByRegID);
        //string strregistrationId = (gvByRegID.SelectedRow.Cells[0]).Text;
        //string country = (gvByRegID.SelectedRow.FindControl("RegistrationID")).ToString;
        //string strregistrationId = (gvByRegID.SelectedRow.Cells[1].Text);
        //string strregistrationId = txtRegNum.Text.Trim();
        //GridViewRow row = gvByRegID.SelectedRow;

        // In this example, the first column (index 0) contains
        //string strregistrationId = row.Cells[0].Text;
        foreach (GridViewRow gr in gvStatusDashboard.Rows)
        {
           
            string strregistrationId;
            strregistrationId = Convert.ToString(gvStatusDashboard.Rows[gr.RowIndex].Cells[0].Text);
            //string cell_2_Value= gvByRegID.Rows[gr.RowIndex].Cells[1].Text; 


            string strValue = string.Empty;
            try
            {
                strValue = (string)new UserMasterBAL().DeleteCandidateAllocation(strregistrationId);

                if (strValue == "SUCCESS")
                {

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Candidate Assessor Allocation deleted succesfully.');", true);
                    gvStatusDashboard.DataBind();

                }
                else if (strValue == "NOTALLOW")
                {

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You have no Rights to delete this Candidate Assessor Allocation.');", true);
                    gvStatusDashboard.DataBind();
                    //lblMessage.Text = "Brief already exists."; //EnrollResources.GetMessage(Message.InsertMessage); //    
                    //lblMessage.ForeColor = System.Drawing.Color.Red;
                }
                else
                {

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Error while deleting Candidate Assessor Allocation.');", true);
                    gvStatusDashboard.DataBind();
                    //lblMessage.Text = "Error while saving Brief."; //EnrollResources.GetMessage(Message.FailedMessage); // 
                    //lblMessage.ForeColor = System.Drawing.Color.Red;
                }


            }
            catch (Exception exception)
            {

                exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);

            }

        }
    }
}